layui.use(['table', 'laydate', 'form' ], function() {
  var table = layui.table;
  var laydate = layui.laydate;
  //日期
  laydate.render({
    elem: '#date',
    type: 'datetime',
    range: true
  });
  var logTable = table.render({
    elem: '#log-table'
    ,title: '用户日志'
    ,url: ctx + 'sys/log/list'
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'id', title:'ID',  fixed: 'left',  sort: true, width: 80}
      ,{field:'username', title:'用户名' , width: 120}
      ,{field:'operation', title:'日志内容' ,width:220}
      ,{field:'method', title:'调用方法', width:220}
      ,{field: 'params', title:'参数'}
      ,{field:'time', title:'响应时间(ms)', width: 120}
      ,{field: 'ip', title:'IP地址'}
      ,{field: 'brower', title:'浏览器'}
      ,{field: 'browerVersion', title:'浏览器版本'}
      ,{field: 'os', title:'操作系统'}
      ,{field: 'createDate', title:'请求时间',width:180}
    ]]
    ,page: true
  });

  $('#query-btn').on('click', function () {
    var usernameVal = $('#username-input').val();
    var timeVal = $('#date').val();
    var where = {}
    if(usernameVal && usernameVal.length > 0) {
      where['userName'] = usernameVal;
    }
    if(timeVal && timeVal.length > 0) {
      where['startTime'] = timeVal.split(" - ")[0];
      where['endTime'] = timeVal.split(" - ")[1];
    }
    console.log(where);
    table.render({
      elem: '#log-table'
      ,title: '用户日志'
      ,url: ctx + 'log/list'
      ,where: where
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field:'id', title:'ID',  fixed: 'left',  sort: true, width: 90}
        ,{field:'username', title:'用户名'}
        ,{field:'operation', title:'日志内容'}
        ,{field:'method', title:'调用方法', width:220}
        ,{field: 'params', title:'参数'}
        ,{field:'time', title:'相应时间(ms)'}
        ,{field: 'ip', title:'IP地址'}
        ,{field: 'brower', title:'浏览器'}
        ,{field: 'browerVersion', title:'浏览器版本'}
        ,{field: 'os', title:'操作系统'}
        ,{field: 'createDate', title:'创建时间'}
      ]]
      ,page: true
    });
  })
});



